package logic

import (
	"context"
	"go.uber.org/zap"
	"smart-health-platforms/pkg"
	"user_srv/internal/svc"
	"user_srv/model"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectAddLogic {
	return &CollectAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectAddLogic) CollectAdd(in *user.CollectAddRequest) (*user.CollectAddResponse, error) {
	collection := &model.Collection{
		UserId: int32(in.UserId),
		GoodId: int32(in.GoodId),
		SkuId:  int32(in.SkuId),
	}
	//调用收藏方法
	err := collection.AddOrUpdateCollection()
	if err != nil {
		pkg.Error("失败", zap.Error(err))
		return nil, err
	}
	//操作成功
	return &user.CollectAddResponse{
		Msg: "收藏成功",
	}, nil
}
